home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / netprog.zip / NETPROG.TAR / ipc / tim_mesg1.c < prev    next >
C/C++ Source or Header  |  1989-12-17  |  1KB  |  66 lines

  1. #include    <stdio.h>
  2. #include    "mesg.h"
  3.  
  4. #define    NUMMESG    10000
  5. #define    MESGLEN    2048
  6.  
  7. Mesg    mesg;
  8.  
  9. client(ipcreadfd, ipcwritefd)
  10. int    ipcreadfd;
  11. int    ipcwritefd;
  12. {
  13.     register int    i, n;
  14.  
  15.     /*
  16.      * Send a message to the server telling it we're here.
  17.      */
  18.  
  19.     mesg.mesg_len = MESGLEN;
  20.     mesg.mesg_type = 1;
  21.     mesg_send(ipcwritefd, &mesg);
  22.  
  23.     /*
  24.      * Then read all the messages from the server.
  25.      */
  26.  
  27.     for (i = 0; i < NUMMESG; i++) {
  28.         mesg.mesg_type = 0;    /* receive first message on queue */
  29.         if ( (n = mesg_recv(ipcreadfd, &mesg)) <= 0)
  30.             err_sys("client: mesg_recv error");
  31.         if (n != MESGLEN)
  32.             err_sys("client: incorrect length");
  33.         if (mesg.mesg_type != (i + 1))
  34.             err_sys("client: incorrect type");
  35.     }
  36. }
  37.  
  38. server(ipcreadfd, ipcwritefd)
  39. int    ipcreadfd;
  40. int    ipcwritefd;
  41. {
  42.     register int    i, n;
  43.  
  44.     /*
  45.      * Wait for a message from the client telling us it's ready.
  46.      */
  47.  
  48.     mesg.mesg_type = 0;    /* receive first message on queue */
  49.     if ( (n = mesg_recv(ipcreadfd, &mesg)) <= 0)
  50.         err_sys("server: mesg_recv error");
  51.     if (n != MESGLEN)
  52.         err_sys("server: incorrect length");
  53.     if (mesg.mesg_type != 1)
  54.         err_sys("server: incorrect type");
  55.  
  56.     /*
  57.      * Now send all the messages to the client.
  58.      */
  59.  
  60.     mesg.mesg_len = MESGLEN;
  61.     for (i = 0; i < NUMMESG; i++) {
  62.         mesg.mesg_type = i + 1;
  63.         mesg_send(ipcwritefd, &mesg);
  64.     }
  65. }
  66.